package com.cxt.controller;

import com.cxt.entity.WaypointInfo;
import com.cxt.result.Result;
import com.cxt.service.IWaypointInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.beans.Transient;

/**
 * <p>
 * 途径点信息表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2025-02-27
 */
@RestController
@RequestMapping("/waypointInfo")
@Slf4j
public class WaypointInfoController {
    @Autowired
    private IWaypointInfoService waypointInfoService;
    /**
     * 添加途径点信息表
     */
    @PostMapping("/add")
    public Result addWaypointInfo(@RequestBody WaypointInfo waypointInfo) {
        log.info("添加途径点信息表");
        boolean isAdd = waypointInfoService.save(waypointInfo);
        if (!isAdd) {
            return Result.error("添加失败");
        }
        return Result.success();
    }
    /**
     * 根据id删除途径点信息表
     */
    @GetMapping("/delete")
    public Result deleteWaypointInfo(Integer id) {
        log.info("删除途径点信息表,id:{}", id);
        boolean isDelete = waypointInfoService.removeById(id);
        if (!isDelete) {
            return Result.error("删除失败");
        }
        return Result.success("删除成功");
    }
    /**
     * 修改途径点信息表
     */
    @PostMapping("/update")
    public Result updateWaypointInfo(@RequestBody WaypointInfo waypointInfo) {
        log.info("修改途径点信息表");
        boolean isUpdate = waypointInfoService.updateById(waypointInfo);
        if (!isUpdate) {
            return Result.error("修改失败");
        }
        return Result.success();
    }
    /**
     * 查询途径点信息表
     */
    @GetMapping("/get")
    @Transient
    public Result getWaypointInfo() {
        log.info("查询途径点信息表");
        return Result.success(waypointInfoService.list());
    }

}
